package com.dfiov.cloud.msmtools.util;

import com.dfiov.cloud.msmtools.enums.ResponseEnum;
import com.pateo.qingcloud.framework.common.base.BaseRestResponse;

/**
 * Response工具类
 */
public class ResponseUtils {

    /**
     * 带参数成功返回
     */
    public static <T>BaseRestResponse<T> success(T data) {
        return new BaseRestResponse<>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg(), data);
    }

    /**
     * 不带参数成功返回
     */
    public static <T>BaseRestResponse<T> success() {
        return new BaseRestResponse<>(ResponseEnum.SUCCESS.getCode(), ResponseEnum.SUCCESS.getMsg(), null);
    }
    /**
     * 带参数错误返回
     */
    public static <T>BaseRestResponse<T> fail(T data) {
        return new BaseRestResponse<>(ResponseEnum.SYSTEM_ERROR.getCode(), ResponseEnum.SYSTEM_ERROR.getMsg(), data);
    }

    /**
     * 不带参数错误返回
     */
    public static <T>BaseRestResponse<T> fail() {
        return new BaseRestResponse<>(ResponseEnum.SYSTEM_ERROR.getCode(), ResponseEnum.SYSTEM_ERROR.getMsg(), null);
    }

    /**
     * 自定义错误码返回
     */
    public static <T>BaseRestResponse<T> fail(ResponseEnum responseEnum, T data) {
        return new BaseRestResponse<>(responseEnum.getCode(), responseEnum.getMsg(), data);
    }
}
